import { defineStore } from 'pinia'


export const useUserStore = defineStore('user', {
	state: () => {
		return {
			longitude: 0, // 经度
			latitude: 0 // 纬度
		}
	},

	getters: {
		location(state) {
			return [state.longitude, state.latitude]
		}
	},

	actions: {
		/**
		 * 获取用户的地理位置
		 */
		async getLocation() {
			console.log('getLocation')
			const resp = await uni.getLocation({
				type: 'gcj02'
			})
			this.longitude = resp.longitude
			this.latitude = resp.latitude
		}
	}
})